package com.bnzj.cloud.business.core.persistence.repository;

import com.bnzj.cloud.business.core.persistence.entity.Group;
import com.bnzj.cloud.business.core.persistence.entity.SysUser;
import com.bnzj.core.persistence.repository.BaseRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author 富
 * @date 2020/5/9 9:21
 */

public interface GroupRepository extends BaseRepository<Group,Long> {


    @Modifying
    @Query("update #{#entityName} set enabled = (?2) where account != 'admin' and id = (?1)")
    void updateGroupById(Long id, boolean sign);

    /**
     * 添加
     * @param group
     */
    @Modifying
    @Query(value = "insert into bnz_group (id, code, gname, sname, email, phone, address, charge_name, charge_phone, remark, enabled, creator, create_time, modify_by, modify_time, creator_name, modify_name) "
            + "values (?#{[0].id}, ?#{[0].code}, ?#{[0].gname}, ?#{[0].sname}, ?#{[0].email},?#{[0].phone},?#{[0].address},?#{[0].charge_name},?#{[0].charge_phone} ,?#{[0].remark},?#{[0].creator},  "
            + "?#{[0].enabled}, ?#{[0].create_time}), ?#{[0].modify_by}, ?#{[0].modify_time} ,?#{[0].creator_name},?#{[0].modify_name}", nativeQuery = true)
    void newSave(Group group);

    @Modifying
    @Query("update #{#entityName} set enabled = (?2) where id = (?1)")
    void updateGroupEnableById(Long id, boolean sign);
}